package com.kfm.hotel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kfm.hotel.anno.Permission;
import com.kfm.hotel.domain.Room;
import com.kfm.hotel.domain.SysDict;
import com.kfm.hotel.service.RoomService;
import com.kfm.hotel.service.SysDictService;
import com.kfm.hotel.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequestMapping("/checkin")
public class CheckinController {

    @Autowired
    private SysDictService sysDictService;

    @Autowired
    private RoomService roomService;

    @GetMapping
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView("checkin/index");
        // 查询所有的房间状态
        modelAndView.addObject("roomStatusList", sysDictService.getByType(1));
        // 查询所有楼层
        List<SysDict> byType = sysDictService.getByType(2);
        modelAndView.addObject("floorList", byType);
        // 把第一个楼层 得房间查询出来
        QueryWrapper<Room> wrapper = new QueryWrapper<>();
        wrapper.eq("floor", byType.get(0).getValue());
        modelAndView.addObject("roomList", roomService.list(wrapper));
        return modelAndView;
    }

    @GetMapping("/vue")
    @Permission("checkin")
    public ModelAndView vue(){
        return new ModelAndView("checkin/index-vue");
    }

    @GetMapping("/checkin/{id}")
    public ModelAndView checkin(@PathVariable Integer id) {
        ModelAndView modelAndView = new ModelAndView("checkin/checkin");
        modelAndView.addObject("id", id);
        return modelAndView;
    }

    @GetMapping("/roomStatusList")
    public R roomStatusList() {
        return R.ok(sysDictService.getByType(1));
    }

    @GetMapping("/floorList")
    public R floorList() {
        return R.ok(sysDictService.getByType(2));
    }

    @GetMapping("/roomList")
    public R roomList(Integer floor) {
        QueryWrapper<Room> wrapper = new QueryWrapper<>();
        wrapper.eq("floor", floor);
        List<Room> list = roomService.listDeep(wrapper);
        return R.ok(list);
    }

}
